<?php
class mysql extends db implements singletoninterface
{
	protected static $instance = NULL;
	protected $link;
	
	public static function getInstance()
	{
		if(is_null(self::$instance)){
			self::$instance = new self;
		}
		
		return self::$instance;
	}
	
	protected function __construct()
	{
		$user = 'picker';
		$pass = 'impicker';
		$host = 'localhost';
		$db = 'picker';
		
		$this->link = mysql_connect($host, $user, $pass)
			or die(lang::COULD_NOT_CONNTECT_DB);
		mysql_select_db($db, $this->link);
		
		mysql_query("SET names utf8");
		mysql_query("SET time_zone = '+8:00'");
	}
	
	public function clean($string)
	{
		return mysql_real_escape_string($string, $this->link);
	}
	
	public function getArray($query)
	{
		$result = mysql_query($query, $this->link);
		
		$return = array();
		if($result){
			while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
				$return[] = $row;
			}
		}
		
		return $return;
	}
	
	public function execute($query)
	{
		mysql_query($query, $this->link);
	}
	
	public function insertGetID($query)
	{
		$this->execute($query);
		return mysql_insert_id($this->link);
	}
}